package com.legendshop.util;

/**
 * 密码检查工具
 */
public class PasswordUtil {

    //密码必须是包含大写字母、小写字母、数字、特殊符号（不是字母，数字，下划线，汉字的字符）的8位以上组合
     private static String PW_PATTERN = "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{8,}$";

    //必须由字母+数字组合，长度大于8位。
    //private static String PW_PATTERN = "^(?![^a-zA-Z]+$)(?!\\D+$).{8,}$";
    //private static String PW_PATTERN = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$";

    public static boolean isPasswordOK(String passwd){
        if(AppUtils.isBlank(passwd)){
            return false;
        }
        return passwd.matches(PW_PATTERN);
    }

    public static void main(String[] args) {
        System.out.println(PasswordUtil.isPasswordOK("1234567"));
        System.out.println(PasswordUtil.isPasswordOK("Aa11234567"));
        System.out.println(PasswordUtil.isPasswordOK("A!11234567"));
        System.out.println(PasswordUtil.isPasswordOK("1Ax!11234567"));
        System.out.println(PasswordUtil.isPasswordOK("Aa!11234567"));
    }
}
